package com.qf.service;/*
 *保护你的大熊
 *2021/11/11
 *21:08
 */

import com.qf.dao.UserMapper;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("userService1")
@Transactional(isolation= Isolation.READ_COMMITTED,propagation= Propagation.REQUIRED,readOnly=false,rollbackFor=Exception.class,timeout = -1)
public class UserServiceImpl implements UserService {

    //在spring核心配置文件中注入使用
    @Autowired
    private UserMapper userMapper;

    //首先properties文件必须被spring核心配置文件引用，交给spring管理
    //然后使用@Value注解根据properties文件中的key获取value值并赋值给一个变量
    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String userName;

//    public void setUserMapper(UserMapper userMapper){
//        this.userMapper = userMapper;
//    }

    @Transactional(propagation=Propagation.SUPPORTS)
    public User findUserById(Integer id) {
        System.out.println("============" + url);
        System.out.println("============" + userName);
        User user = userMapper.findUserById(id);

        return user;
    }

    public void insertUser(User user) {
        userMapper.insertUser(user);
        int i = 1/0;
    }
}
